﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace calendar
{
/**
* This class represents instances of Calendar Exception records from
* an MPX file. It is used to define exceptions to the working days described
* in both base and resource calendars.
*/

public sealed class ProjectCalendarException : ProjectCalendarDateRange , IComparable<ProjectCalendarException>
{

    private DateTime m_fromDate;
    private DateTime m_toDate;

    public ProjectCalendarException(DateTime fromDate, DateTime toDate)
    {
        m_fromDate = DateUtility.getDayStartDate(fromDate);
        m_toDate = DateUtility.getDayEndDate(toDate);
    }

    public DateTime FromDate
    {
        get { return m_fromDate; }
    }

    public DateTime ToDate
    {
        get { return m_toDate; }
    }

    public bool isWorking
    {
        get
        {
            bool result = (getRangeCount() != 0);
            return result;
        }
    }

    public bool contains(DateTime date)
    {
        bool result = false;
        if (date != null)
        {
            result = (DateUtility.compare(m_fromDate, m_toDate, date) == 0);
        }
        return result;
    }

    int IComparable<ProjectCalendarException>.CompareTo(ProjectCalendarException other)
    {
        long A = m_fromDate.Ticks;
        long B = other.FromDate.Ticks;
        return ((A < B) ? (-1) : ((A == B) ? 0 : 1));        
    }

    public override string ToString()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("[ProjectCalendarException");
        sb.Append(" working = " + this.isWorking);
        sb.Append(" fromDate = " + this.m_fromDate);
        sb.Append(" toDate = " + this.m_toDate);

        foreach (DateRange dr in this)
        {
            sb.Append(dr.ToString());
        }
        sb.Append("]");
        return sb.ToString();
    }
}
}
